package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import DataObjects.Menu;

public class PfStandardMenus extends JPanel{
	private MainMenu mainMenu;
	private Vector<Menu> allTheMenus;
	private int x;
	private int y;
	private Dimension screenSize;
	
	public  PfStandardMenus(MainMenu mm,Vector<Menu> theMenus )
	{
		super();
		//this.setLayout(null);
		//this.setLayout(new BorderLayout());
		
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		this.mainMenu=mm;
		this.allTheMenus=theMenus;
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		initialize();
	}
	
	
	private void	initialize()
	{
		this.add(getPanelMenu());
	
	}
	
	
	private  JPanel getPanelMenu()
	{
		JPanel	panel_menu=new JPanel();
		
		//this.setLayout(null);
		panel_menu.setLayout(new BoxLayout(panel_menu, BoxLayout.X_AXIS));
		//panel_menu.setLayout(new FlowLayout(FlowLayout.LEFT,5,5));
		final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
		//tabbedPane.setBounds(750, 500, 70, 70);
		
		//tabbedPane.setSize(60, 80);
		
         for(int i=0;i<allTheMenus.size();i++){
			
			if(allTheMenus.get(i).getType().equals("simple"))
			
	            tabbedPane.addTab(allTheMenus.get(i).getName() ,  getPanelStandardsMenus(allTheMenus.get(i)) );
                                              } //for
	    
	  panel_menu.add(tabbedPane, BorderLayout.CENTER);
	    
		return panel_menu;
	}
	
	private JPanel getPanelStandardsMenus(Menu menuStandard)
	{
		Menu menu = new Menu();
		menu=menuStandard;
		JPanel	panel_menuDrink=new JPanel();
		panel_menuDrink.setLayout(null);
		x=screenSize.width;
		y=screenSize.height;
		//-----used for based labels proportion display
				y=y/100;
				       
		      for(int j=0;j<menu.getRecipes().size();j++)
		       {
		    	  JLabel nameRecipe =new JLabel();
		    	  nameRecipe.setForeground(new Color(150, 100, 153));
				   nameRecipe.setFont(new Font("Tahoma", Font.BOLD | Font.PLAIN, 15));
			       
			       //-----Label for a price of recipe
			       JLabel priceRecipe =new JLabel();
			       priceRecipe.setForeground(new Color(160, 82, 45));
			       priceRecipe.setFont(new Font("Tahoma", Font.BOLD | Font.PLAIN, 15));
		    	  
		       String text1 = (String) menu.getRecipes().get(j).getName();   //name
		       String text2 = (String) menu.getRecipes().get(j).getPrice();  //price
		       
		      //---------Pomogaet uznat zaranee razmer teksta  chtobi podstroit razmer leibla avtomatom--->TextLayout(nash tekst,nash shrift,...)
		       
		       TextLayout tl1 = new TextLayout(text1,new Font("Tahoma", Font.BOLD | Font.PLAIN, 15) , new FontRenderContext(null, true, true)); //size of name (size of string)
		       TextLayout tl2 = new TextLayout(text2,new Font("Tahoma", Font.BOLD | Font.PLAIN, 15) , new FontRenderContext(null, true, true)); //size of  price (size of string)
		       
		       nameRecipe.setText(text1);
		       priceRecipe.setText(text2    +" ש''ח");
		       nameRecipe.setBounds(750, y, (((int) tl1.getBounds().getCenterX())*2), (int) tl1.getBounds().getHeight());
		       priceRecipe.setBounds(650, y, (((int) tl1.getBounds().getCenterX())*2)+10, (int) tl1.getBounds().getHeight());
		       y=y+28;
		       panel_menuDrink.add(nameRecipe);
		       panel_menuDrink.add(priceRecipe);
		       }  //for
		
				
		return panel_menuDrink;
	}
	

	
}
